﻿using Hotel.Application.Admins.Dto;
using Hotel.Application.Admins;
using Hotel.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hotel.Application.DicTypes.Dto;
using Hotel.Repositories;
using AutoMapper;

namespace Hotel.Application.DicTypes
{
    public class DicTypeService : BaseService<DicType, DicTypeCreateUpdateDto, DicTypeListDto>, IDicTypeService
    {
        private readonly IRepository<DicType> repository;

        public DicTypeService(IRepository<DicType> repository) : base(repository)
        {
            this.repository = repository;
        }

        public async Task<ResultDto<bool>> CheckName(string TypeName, string TypeCode, long TypeId)
        {
            return new ResultDto<bool>
            {
                code = State.Success,
                data = await repository.AnyAsync(m => (m.TypeName == TypeName || m.TypeCode == TypeCode) && m.TypeId != TypeId)
            };
        }
    }
}
